package com.wkbb.basic.controller.open;

import com.wkbb.basic.model.Position;
import com.wkbb.basic.service.PositionService;
import com.wkbb.common.base.BaseController;
import com.wkbb.common.constants.ErrorCode;
import com.wkbb.common.constants.VersionConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.OrgTypeDto;
import com.wkbb.common.dto.basic.PositionDto;
import com.wkbb.common.enums.OrganizationTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 岗位相关接口
 *
 * @author Alger Yang
 */
@Api(description = "岗位相关接口")
@RestController
@RequestMapping("/basic/{apiVersion}/open")
@Slf4j
public class PositionController extends BaseController {

    @Autowired
    private PositionService positionService;

    @ApiOperation(value = "岗位")
    @RequestMapping(value = "/getPositionList", method = RequestMethod.GET)
    public ResultDTO<List<PositionDto>> getPositionList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织类型(1微看 2代理商 3机关 4培训学校 5幼儿园 6小学 7中学 8高中 9大学 10职业学校)", required = true) @RequestParam(name = "orgType") Integer orgType) {
        try {

            Map<String, Object> queryParams = new HashMap<>();
            queryParams.put("orgType", orgType);

            List<PositionDto> positionList = new ArrayList<PositionDto>();
            List<Position> list = positionService.getListByMapParams(queryParams);
            for(Position position : list)
            {
                PositionDto positionDto = new PositionDto();
                positionDto.setId(position.getId());
                positionDto.setOrgType(position.getOrgType());
                positionDto.setPositionName(position.getPositionName());

                positionList.add(positionDto);
            }

            return new ResultDTO<List<PositionDto>>(positionList);
        } catch (Exception e) {
            log.error("***********PositionController.getPositionList******", e);
            return new ResultDTO(ErrorCode.SYSTEM_EXCEPTION);
        }
    }
}
